package com.gupao.gupaoeduvippattern.javaBase.thread.day01_4;

/**
 * @author Administrator
 * @date 2020-12-06 15:25
 */
public class PriorityDemo {

    /**
     * 线程的执行 与 操作系统的环境和CPU的执行调度有很大关系的
     *
     * @param args
     */
    public static void main(String[] args) {
        int priority = Thread.currentThread().getPriority();
        System.out.println(Thread.currentThread().getName() + "：主线程的优先级" + priority);

        MyThread mt1 = new MyThread("A");
        MyThread mt2 = new MyThread("B");
        System.out.println(mt1.getPriority()+","+mt2.getPriority());

        mt1.setPriority(Thread.MAX_PRIORITY);
        mt1.start();

        mt2.setPriority(Thread.MIN_PRIORITY);
        mt2.start();

        System.out.println("主线程："+mt1.getPriority()+","+mt2.getPriority());
    }

}

class MyThread extends Thread{

    private String name;

    public MyThread(String name){
        this.name = name;
    }

    public void run(){
        for(int i=1; i<=50; i++){
            System.out.println(name + "运行次数" + i);
        }
    }

}
